<%@ taglib prefix="C" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if !IE]><!-->
<html lang="zh">
<!--<![endif]-->
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
%>

<head>
    <meta charset="utf-8"/>
    <%@include file="../common/taglib.jsp" %>
    <title>保险代理后台管理系统</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
    <meta content="" name="description"/>
    <meta content="" name="author"/>
    <jsp:include page="../common/header.jsp"></jsp:include>
    <style>
        body {
            background: white;
        }
    </style>
</head>
<body>
<section>
    <%--<ul class="nav nav-pills">
        <li class="active"><a href="#tab1" data-toggle="tab">保单信息</a></li>
    </ul>
    <hr>--%>
    <div class="form-wrap">
        <div class="tab-content">
            <div id="tab1" class="tab-pane fade active in">
                <div>
                    <h4>投保客户信息</h4>
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">保单号：</label>
                            <div class="col-sm-10">
                                <p class="form-control-static">${orderInfo.ordNum}</p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">车主：</label>
                            <div class="col-sm-10">
                                <p class="form-control-static">${orderInfo.carOwner}</p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">车牌号：</label>
                            <div class="col-sm-10">
                                <p class="form-control-static">${orderInfo.plateNum}</p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">车架号：</label>
                            <div class="col-sm-10">
                                <p class="form-control-static">${orderInfo.engineNum}</p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">车辆种类：</label>
                            <div class="col-sm-10">
                                <p class="form-control-static">
                                    <c:choose>
                                        <c:when test="${orderInfo.vehicleType == 1}">客车</c:when>
                                        <c:when test="${orderInfo.vehicleType == 2}">货车</c:when>
                                    </c:choose>
                                </p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">被保险人：</label>
                            <div class="col-sm-10">
                                <p class="form-control-static">${orderInfo.insurant}</p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">被保险人身份证号/<br>组织机构代码：</label>
                            <div class="col-sm-10">
                                <p class="form-control-static">${orderInfo.orgIdCode}</p>
                            </div>
                        </div>
                        <c:if test="${orderInfo.typeInvestment == 1}">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">前保险公司：</label>
                                <div class="col-sm-10">
                                    <p class="form-control-static">${orderInfo.preInsyrer}</p>
                                </div>
                            </div>
                        </c:if>
                        <c:if test="${orderInfo.typeInvestment == 0}">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">发动机号：</label>
                                <div class="col-sm-10">
                                    <p class="form-control-static">${orderInfo.engineNum}</p>
                                </div>
                            </div>
                        </c:if>
                    </div>
                </div>
                <div>
                    <h4>保险信息</h4>
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">保险公司：</label>
                            <div class="col-sm-10">
                                <p class="form-control-static">${orderInfo.insyrerName}</p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">险种：</label>
                            <div class="col-sm-10">
                                <c:choose>
                                    <c:when test="${orderInfo.typeInsurance==0}">
                                        <p class="form-control-static">交强险</p>
                                    </c:when>
                                    <c:when test="${orderInfo.typeInsurance==1}">
                                        <p class="form-control-static">商业险</p>
                                    </c:when>
                                </c:choose>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">保险期限：</label>
                            <div class="col-sm-10">
                                <p class="form-control-static">${orderInfo.insureStartDate}至${orderInfo.insureEndDate}</p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">垫资类型：</label>
                            <div class="col-sm-10">
                                <c:choose>
                                    <c:when test="${orderInfo.typeInsurance2==1}">
                                        <p class="form-control-static">不垫资</p>
                                    </c:when>
                                    <c:when test="${orderInfo.typeInsurance2==2}">
                                        <p class="form-control-static">垫返点</p>
                                    </c:when>
                                    <c:when test="${orderInfo.typeInsurance2==3}">
                                        <p class="form-control-static">垫保费</p>
                                    </c:when>
                                </c:choose>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">垫资账期：</label>
                            <div class="col-sm-10">
                                <p class="form-control-static">${orderInfo.laonAccount} 天</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="panel-body panel-form">
                    <form class="form-horizontal" data-parsley-validate="true" name="form-wizard" id="chackOrderForm">
                        <div class="wizard-step-1">
                            <div class="form-group">
                                <label class="control-label col-sm-2"
                                       for="themeKey">付款主体：</label>
                                <div class="col-md-4">
                                    <select class="form-control" id="themeKey" name="themeKey"
                                            onchange="reCalRebateRate()"
                                            data-parsley-group="wizard-step-1"
                                            data-parsley-required="true"
                                            data-parsley-required-message="付款主体必填">
                                        <option value="">请选择</option>
                                        <c:forEach var="theme" items="${payThemeList }">
                                            <option value="${theme.riskKey}">${theme.riskValue}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <c:choose>
                                    <c:when test="${orderInfo.typeInsurance==0}">
                                        <label class="control-label col-sm-2">交强险保费：</label>
                                    </c:when>
                                    <c:otherwise>
                                        <label class="control-label col-sm-2">商业险保费：</label>
                                    </c:otherwise>
                                </c:choose>
                                <div class="col-md-4">
                                    <div class="input-group">
                                        <input class="form-control" type="text"
                                               onblur="calcAllPremium(${orderInfo.typeInsurance})"
                                               id="insurance" name="premium" onchange="reCalRebateRate()"
                                               data-parsley-group="wizard-step-1"
                                               data-parsley-required="true" data-parsley-required-message="保费必填"
                                               data-parsley-money="true" data-parsley-money-message="数字格式不正确"/>
                                        <div class="input-group-addon">元</div>
                                    </div>
                                </div>
                            </div>
                            <c:choose>
                                <c:when test="${orderInfo.typeInsurance==0}">
                                    <div class="form-group">
                                        <label class="control-label col-sm-2"
                                               for="vehicleTex">车船税：</label>
                                        <div class="col-md-4">
                                            <div class="input-group">
                                                <input class="form-control" type="text"
                                                       onblur="calcAllPremium(${orderInfo.typeInsurance})"
                                                       id="vehicleTex" name="vehicleTex" onchange="reCalRebateRate()"
                                                       data-parsley-group="wizard-step-1"
                                                       data-parsley-required="true"
                                                       data-parsley-required-message="车船税必填"
                                                       data-parsley-money="true" data-parsley-money-message="数字格式不正确"/>
                                                <div class="input-group-addon">元</div>
                                            </div>
                                        </div>
                                    </div>
                                </c:when>
                            </c:choose>
                            <div class="form-group">
                                <c:choose>
                                    <c:when test="${orderInfo.typeInsurance==0}">
                                        <label class="control-label col-sm-2"
                                               for="followTicketPoint">交强险跟单点位：</label>
                                    </c:when>
                                    <c:otherwise>
                                        <label class="control-label col-sm-2"
                                               for="followTicketPoint">商业险跟单点位：</label>
                                    </c:otherwise>
                                </c:choose>
                                <div class="col-md-4">
                                    <div class="input-group">
                                        <input class="form-control" type="text" id="followTicketPoint"
                                               name="followPoint" onchange="reCalRebateRate()"
                                               data-parsley-group="wizard-step-1"
                                               data-parsley-required="true" data-parsley-required-message="跟单点位必填"
                                               data-parsley-point="true" data-parsley-point-message="数字格式不正确"/>
                                        <div class="input-group-addon">%</div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <c:choose>
                                    <c:when test="${orderInfo.typeInsurance==0}">
                                        <label class="control-label col-sm-2"
                                               for="supplementPoint">交强险补单点位：</label>
                                    </c:when>
                                    <c:otherwise>
                                        <label class="control-label col-sm-2"
                                               for="supplementPoint">商业险补单点位：</label>
                                    </c:otherwise>
                                </c:choose>
                                <div class="col-md-4">
                                    <div class="input-group">
                                        <input class="form-control" type="text" id="supplementPoint"
                                               name="supplementPoint" onchange="reCalRebateRate()"
                                               data-parsley-group="wizard-step-1"
                                               data-parsley-required="true" data-parsley-required-message="补单点位必填"
                                               data-parsley-point="true" data-parsley-point-message="数字格式不正确"/>
                                        <div class="input-group-addon">%</div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2"
                                       for="remark">&nbsp;</label>
                                <div class="col-md-4">
                                    <button type="button" id="calcRebateRateButton" onclick="calcRebateRate()"
                                            class="btn btn-primary m-r-10">计算保费
                                    </button>
                                    <button type="button" id="resetOrderOne" onclick="resetOrder('1')"
                                            class="btn btn-default">驳回
                                    </button>
                                </div>
                            </div>
                        </div>
                        <div id="costTotal" class="hidden">
                            <h3>费用合计</h3>
                            <div class="form-group">
                                <label class="control-label col-sm-2">全保费：</label>
                                <div class="col-md-4">
                                    <div class="input-group">
                                        <input class="form-control" type="text" readonly="readonly"
                                               id="allPremiumSpan"/>
                                        <div class="input-group-addon">元</div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">税后保费：</label>
                                <div class="col-md-4">
                                    <div class="input-group">
                                        <input class="form-control" type="text" readonly="readonly"
                                               id="texPremiumSpan"/>
                                        <div class="input-group-addon">元</div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">参考渠道返点：</label>
                                <div class="col-md-4">
                                    <div class="input-group">
                                        <input class="form-control" type="text" readonly="readonly"
                                               id="channelLookPointSpan"/>
                                        <div class="input-group-addon">%</div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2"
                                       for="channelPoint">渠道返点：</label>
                                <div class="col-md-4">
                                    <div class="input-group">
                                        <input class="form-control" type="text" id="channelPoint"
                                               name="channelPoint" onblur="calRebateFee()"
                                               data-parsley-required="true" data-parsley-required-message="渠道返点必填"
                                               data-parsley-point="true" data-parsley-point-message="数字格式不正确"/>
                                        <div class="input-group-addon">%</div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2"
                                       for="channelRebateFee">渠道返佣费：</label>
                                <div class="col-md-4">
                                    <div class="input-group">
                                        <input class="form-control" type="text" readonly="readonly"
                                               id="channelRebateFee"/>
                                        <div class="input-group-addon">元</div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">渠道应支付保费：</label>
                                <div class="col-md-4">
                                    <div class="input-group">
                                        <input class="form-control" type="text" readonly="readonly"
                                               id="channelPayPremiumSpan"/>
                                        <div class="input-group-addon">元</div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2"
                                       for="remark">审核意见：</label>
                                <div class="col-md-4">
                                        <textarea class="form-control" id="remark" name="remark"
                                                  rows="4"
                                                  data-parsley-required="true"
                                                  data-parsley-required-message="审核意见必填"
                                                  data-parsley-maxlength="100"
                                                  data-parsley-maxlength-message="审核意见的最大长度是100"
                                                  placeholder=""></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2"
                                       for="remark">&nbsp;</label>
                                <div class="col-md-4">
                                    <button type="button" id="passButton" onclick="passOrder()"
                                            class="btn btn-primary m-r-10">
                                        通过
                                    </button>
                                    <button type="button" id="resetOrderTwo" onclick="resetOrder('2')"
                                            class="btn btn-default">驳回
                                    </button>
                                </div>
                            </div>
                        </div>
                        <input id="orderId" name="tid" value="${orderInfo.tid}" hidden/>
                        <input id="productId" name="productId" value="${orderInfo.productId}" hidden/>
                        <input id="typeInsurance2" value="${orderInfo.typeInsurance2}" hidden/>
                        <input id="allPremiumInput" name="allPremium" hidden/>
                        <input id="channelPayPremiumInput" name="channelPayPremium" hidden/>
                        <input id="texPremiumInput" name="texPremium" hidden/>
                        <input id="channelLookPointInput" name="channelLookPoint" hidden/>
                        <input id="channelRebateFeeInput" name="channelRebateFee" hidden/>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>
<table class="bg-warning">
    <thead>
    <tr>
        <th>操作记录</th>
        <th>操作人</th>
        <th>操作时间</th>
        <th>备注</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${optionList}" var="opt">
        <tr>
            <td>${opt.content}</td>
            <td>${opt.createUser.roleName}(${opt.createUser.realName})</td>
            <td><javatime:format value="${opt.createAt}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
            <td>${opt.remark}</td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<!-- end page container -->
<jsp:include page="../common/footer.jsp"/>
<script type="text/javascript">
    $(document).ready(function () {
        App.init();
        TableManageFixedHeader.init();
    });
    /**
     * 审核驳回
     */
    function resetOrder(type) {
        if(type==1){

        }else{

        }
        var ordId = $("#orderId").val();
        $.ajax({
            url: "/ins/order/checkReset",
            asyno: false,
            data: {"tid": ordId},
            success: function (data) {
                if (data.success == false) {
                    alert(data.msg);
                } else {
                    window.parent.location.href = "/ins/order/skipOrderList";
                }
            },
            error: function (data) {
                console.log(data);
            }
        });
    }
    /**
     * 计算全保费
     * @param typeInsurance 险种类型 0 交强险、1 商业险
     */
    function calcAllPremium(typeInsurance) {
        var insurance = $("#insurance").val();
        var vehicleTexVal = $("#vehicleTex").val();
        $.ajax({
            url: "/ins/order/calcAllPremium",
            type: "POST",
            data: {"insurance": insurance, "vehicleTexVal": vehicleTexVal},
            success: function (data) {
                var allPremium = data.allPremium;
                $("#allPremiumSpan").val(allPremium);
                $("#allPremiumInput").val(allPremium);
            }
        })
    }

    /**
     * 计算渠道返点
     */
    function calcRebateRate() {
        if ($("#chackOrderForm").parsley().validate("wizard-step-1")) {
            var productIdValue = $("#productId").val();
            var typeValue = $("#typeInsurance2").val();
            var paymentDaysValue = $("#laonAccount").val();
            var allPremiumValue = $("#allPremiumInput").val();
            var paySubjectValue = $("#themeKey option:selected").val();
            var followTicketPointValue = $("#followTicketPoint").val();
            var supplementPointValue = $("#supplementPoint").val();
            $.ajax({
                url: "/product/getRebateAndMoney",
                type: "POST",
                data: {
                    productId: productIdValue,
                    type: typeValue,
                    paymentDays: paymentDaysValue,
                    allPremium: allPremiumValue,
                    paySubject: paySubjectValue,
                    followTicketPoint: followTicketPointValue,
                    supplementPoint: supplementPointValue
                },
                async: false,
                success: function (data) {
                    if (data.success) {
                        $("#costTotal").removeClass("hidden");
                        $("#passButton").removeAttr("disabled");
                        $("#calcRebateRateButton").attr("disabled", "disabled");
                        $("#resetOrderOne").addClass("hidden");
                        $("#channelLookPointSpan").val(data.result.channelRebate);
                        $("#channelLookPointInput").val(data.result.channelRebate);
                        $("#texPremiumSpan").val(data.result.texPremium);
                        $("#texPremiumInput").val(data.result.texPremium);
                        var s = parent.document.getElementById('iframeParent');
                        function setIframeHeight() {
                            s.style.height = document.body.offsetHeight + 'px';
                        }
                        setTimeout(function () {
                            setIframeHeight();
                        }, 200);
                    } else {
                        $("#calcRebateRateButton").addClass("hidden")
                        $("#costTotal").addClass("hidden");
                        alert(data.msg);
                    }
                },
                error: function (data) {
                    console.log(data);
                }
            })
        }
    }
    /**
     * 多次计算渠道返点流程控制
     */
    function reCalRebateRate() {
        $("#calcRebateRateButton").removeAttr("disabled");
        $("#passButton").attr("disabled", "disabled");
        $("#costTotal").addClass("hidden");
    }
    /**
     * 计算渠道返佣费和渠道应支付保费
     */
    function calRebateFee() {
        var allP = $("#allPremiumInput").val();
        var channelPit = $("#channelPoint").val();
        var type = $("#typeInsurance2").val();
        $.ajax({
            url: "/ins/order/calRebateFee",
            type: "POST",
            data: {"allP": allP, "channelPit": channelPit,"type":type},
            success: function (data) {
                $("#channelPayPremiumInput").val(data.channelMustPay);
                $("#channelPayPremiumSpan").val(data.channelShowPay);
                $("#channelRebateFeeInput").val(data.channelRebate);
                $("#channelRebateFee").val(data.channelRebate)
            }
        })
    }
    /**
     * 审核通过
     */
    function passOrder() {
        if ($('#chackOrderForm').submit().parsley().isValid()) {
            $.ajax({
                url: "/ins/order/passOrder",
                async: false,
                type: "POST",
                data: $('#chackOrderForm').serialize(),
                success: function (data) {
                    if (data.success == false) {
                        alert(data.msg);
                    } else {
                        window.parent.location.href = "/ins/order/skipOrderList";
                    }
                }
            });
        }
    }
    window.onload = function () {
        var s = parent.document.getElementById('iframeParent');
        var $tabPane = $('.tab-pane');

        function setIframeHeight() {
            s.style.height = document.body.offsetHeight + 'px';
        }

        setIframeHeight();

        $(".nav").find("li").click(function () {
            var $index = $(this).index();
            $tabPane.eq($index).addClass('aa')
            setTimeout(function () {
                if ($tabPane.eq($index).hasClass('active')) {
                    setIframeHeight();
                }
            }, 200);
        });
    }

</script>
<!-- ================== END PAGE LEVEL JS ================== -->
</body>
</html>
